package com.client.utility;

import java.io.IOException;

import com.client.bean.BaseResponseBean;
import com.ning.http.client.Response;

public class HttpResponseUtility {
	public static <T> BaseResponseBean<T> getResponse(Response response,Class<T> clazz){
		BaseResponseBean<T> responseBean = new BaseResponseBean<T>();
		if(response == null) {
			return responseBean;
		}
		
		if(response.getStatusCode() != BaseResponseBean.HTTP_SUCCESS) {
			responseBean.setCode(response.getStatusCode());
			return responseBean;
		}
		
		try {
			responseBean.setResult(JsonUtility.StrToEntity(response.getResponseBody("UTF-8"), clazz));
			responseBean.setCode(BaseResponseBean.SUCCESS);
			return responseBean;
		}catch(IOException e) {
			return responseBean;
		}
	}
	
}
